﻿using System;
using System.Configuration;


namespace DAL.Gateway
{
    public class Config
    {
        public static string ConnectionString
        {
            get
            {
                try
                {
                    return ConfigurationManager.ConnectionStrings[Config.ConnectionStringName].ToString();
                }
                catch (Exception ex)
                {
                    throw new Exception("Config - ConnectionString - No se encuentra la cadena de conexión.", ex);
                }
            }
        }
        public static string ConnectionStringName
        {
            get
            {
                try
                {
                    return ConfigurationManager.AppSettings["ConnectionStringName"].ToString();
                }
                catch (Exception ex)
                {
                    throw new Exception("Config - ConnectionString - No se encuentra el nombre de la cadena de conexión.", ex);
                }
            }
        }
        public static DAL.Gateway.EDBMS DBTYPE
        {
            get
            {
                try
                {
                    DAL.Gateway.EDBMS dbtype = Gateway.EDBMS.SqlServer;
                    
                    switch (ConfigurationManager.AppSettings["DBTYPE"].ToString().ToUpper())
                    {
                        case "FIREBIRD":
                            dbtype = Gateway.EDBMS.Firebird;
                            break;
                        case "MYSQL":
                            dbtype = Gateway.EDBMS.MySql;
                            break;
                        case "ORACLE":
                            dbtype = Gateway.EDBMS.Oracle;
                            break;
                        case "POSTGRESQL":
                            dbtype = Gateway.EDBMS.PostgreSQL;
                            break;
                        case "MSACCESS":
                            dbtype = Gateway.EDBMS.MSAccess;
                            break;
                        case "HSQLDB":
                            dbtype = Gateway.EDBMS.HSQLDB;
                            break;
                        default:
                            dbtype = Gateway.EDBMS.SqlServer;
                            break;
                    }
                    return dbtype;
                }
                catch (Exception ex)
                {
                    throw new Exception("Config - DBTYPE - El tipo de conector no ha sido establecido.", ex);
                }
            }
        }
    }
}
